{% extends "base.html" %}
{% block  title %}资产用户{% endblock %}
{% block header-css %}

    {% load bootstrap3 %}
{% endblock %}


{% block  page-content %}

    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-lg-10">
            <h2>资产用户</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="/index.html">主页</a>
                </li>
                <li>
                    <a>资产管理</a>
                </li>
                <li class="active">
                    <strong>管理资产</strong>
                </li>
            </ol>
        </div>
        <div class="col-lg-2">

        </div>
    </div>

    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="panel-options">
                        <ul class="nav nav-tabs">

                            <li>
                                <a href="{% url  "asset:asset_user_detail"  pk=nid %}" class="text-center"><i
                                        class="fa fa-laptop"></i>资产用户</a>
                            </li>
                            <li class="active">

                                <a class="text-center" href="{% url  "asset:asset_user_asset"   pk=nid %}"><i
                                        class="fa fa-laptop"></i>管理资产</a>
                            </li>


                            <li class="pull-right">
                                <a class="btn btn-outline btn-default"
                                   href="{% url "asset:asset_user_update"  nid %}"><i
                                        class="fa fa-edit"></i>编辑</a>
                            </li>
                            <li class="pull-right">
                                <a class="btn btn-outline btn-danger  asset_user_del">
                                    <i class="fa fa-edit"></i>删除
                                </a>
                            </li>

                        </ul>
                    </div>
                    <div class="ibox-title">
                        <h5>关联资产</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="#">选项 1</a>
                                </li>
                                <li><a href="#">选项 2</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">

                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover dataTables-example">
                                <thead>
                                <tr>

                                    <th>主机名</th>
                                    <th>内网IP</th>
                                    <th>外网IP</th>
                                    <th>平台</th>

                                    <th>项目</th>
                                    <th>动作</th>

                                </tr>
                                </thead>
                                <tbody>

                                {% for   row   in   assets_list %}
                                    <tr class="gradeA" id="{{ row.id }}">

                                        <td class="center"><a
                                                href="{% url  "asset:asset_detail"   pk=row.id %}">{{ row.hostname }}</a>
                                        </td>
                                        <td class="center">{{ row.network_ip }}</td>
                                        <td class="center">{{ row.inner_ip }}</td>
                                        <td class="center">{{ row.platform }} -- {{ row.region }}</td>

                                        <td class="center">{{ row.project }}</td>
                                        <td><a class="btn btn-primary  btn-xs "
                                               href="{% url  "asset:asset_update"  pk=row.id %}">编辑</a>
                                            <a class="btn btn-danger  btn-xs  asset_del"
                                            >删除</a></td>

                                    </tr>
                                {% endfor %}

                                </tbody>
                                <tfoot>
                                <tr>

                                    <th>主机名</th>
                                    <th>外网IP</th>
                                    <th>内网IP</th>
                                    <th>平台</th>

                                    <th>项目</th>
                                    <th>动作</th>

                                </tr>
                                </tfoot>
                            </table>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>




    {% block footer-js %}


        <script>


            $(function () {

                $(document).on('click', '.asset_del', function () {
                    var id = $(this).parent().parent().attr('id');
                    swal({
                        title: "你确定删除",
                        text: "你将无法恢复",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",
                        closeOnConfirm: false
                    }, function () {
                        $.ajax({
                            headers: {"X-CSRFToken": '{{ csrf_token }}'},
                            url: "/asset/asset-all-del.html",
                            type: 'POST',
                            data: {'nid': id},
                            success: function (data) {
                                var obj = JSON.parse(data);
                                if (obj.status) {
                                    swal({title: "删除", text: "已成功删除", type: "success"}, function () {
                                        window.location.reload();
                                    })
                                } else {
                                    swal("错误", "删除" + "[ " + obj.error + " ]" + "遇到错误", "error");
                                }
                            }
                        });


                    });

                });


                $('.asset_user_del').click(function () {
                    swal({

                        title: "你确定删除",
                        text: "你将无法恢复",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",
                        closeOnConfirm: false
                    }, function () {
                        $.ajax({
                            url: "/asset/asset-user-all-del.html",
                            type: 'POST',
                            data: {'nid': {{  nid }}},
                            success: function (data) {

                                var obj = JSON.parse(data);
                                if (obj.status) {
                                    swal({title: "删除", text: "已成功删除", type: "success"}, function () {
                                        location.href = "{% url "asset:asset_list" %}"
                                    })
                                } else {
                                    swal("错误", "删除" + "[ " + obj.error + " ]" + "遇到错误", "error");
                                }
                            }
                        });


                    });
                });


            });


        </script>


    {% endblock %}


{% endblock %}


